package org.pan.domain.enums;

/**
 * 门禁刷卡事件类型
 *
 * Created by panmingzhi on 2015/12/25.
 */
public enum EventTypeEnum {
    /**
     * 正常刷卡
     */
    NormalSwipe(0x41, "正常刷卡"),
    /**
     * 非法刷卡
     */
    IllegalSwipe(0x42, "非法刷卡"),
    /**
     * 正常开门 (DLS), 外手柄开门 (DLL)
     */
    NormalOpenDoor(0x43, "正常开门"),
    /**
     * 内手柄开门
     */
    OpenDoorInsde(0x44, "内手柄开门"),
    /**
     * 非法开门
     */
    IllegalOpenDoor(0x45, "非法开门"),
    /**
     * 机械钥匙开门
     */
    KeyOpenDoor(0x46, "机械钥匙开门"),
    /**
     * 消防报警
     */
    FireAlarm(0x47, "消防报警"),
    /**
     * 防拆报警
     */
    BreakAlarm(0x48, "防拆报警"),
    /**
     * 密码开门
     */
    OpenDoorWithPass(0x49, "密码开门"),
    /**
     * 内读头正常刷卡
     */
    InternalReaderNormalSwipe(0x4A, "内读头正常刷卡"),
    /**
     * 内读头非法刷卡
     */
    InternalReaderIllegalSwipe(0x4B, "内读头非法刷卡"),
    /**
     * 出门开关
     */
    OpenDoorWithSwitch(0x4D, "出门开关"),
    /**
     * 电脑远程开门
     */
    OpenDoorRemotely(0x4F, "电脑远程开门"),
    /**
     * 门虚掩报警
     */
    DoorNotClosedAlarm(0x50, "门虚掩报警"),
    /**
     * 紧急按钮
     */
    EmergencyButtonPressed(0x51, "紧急按钮"),
    /**
     * 电脑远程关门
     */
    CloseDoorRemotely(0x52, "电脑远程关门"),

    Error(0x00, "未知动作"),

    CarparkNormalSwipe(0x0A, "停车场正常刷卡"),

    CarparkIllegalSwipe(0x0A, "停车场非法刷卡"),

    PositionNumberOutRecord(0x5A, "车位计数出场"),

    PositionNumberInRecord(0x59, "车位计数入场"),

    CarparkOpenDoorWithHand(0x0C, "停车场手动开闸"),

    AttendancePostCard(0x0D, "考勤打卡");

    private final int ascii;
    private String description;

    EventTypeEnum(int ascii, String description) {
        this.ascii = ascii;
        this.description = description;
    }

    public byte getAsciiValue() {
        return (byte) this.ascii;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return this.description;
    }

    public static EventTypeEnum parse(int ascii) {
        EventTypeEnum[] values = EventTypeEnum.values();
        for (EventTypeEnum eventTypeEnum : values) {
            if (eventTypeEnum.getAsciiValue() == ascii)
                return eventTypeEnum;
        }
        return EventTypeEnum.Error;
    }

    public static EventTypeEnum parse(String name) {
        EventTypeEnum[] values = EventTypeEnum.values();
        for (EventTypeEnum eventTypeEnum : values) {
            if (eventTypeEnum.getDescription().equals(name))
                return eventTypeEnum;
        }
        return EventTypeEnum.Error;
    }

}
